/**
 * \file map.h
 * \brief Map, an unordered key->value datatype.
 **/

#ifndef R_MAP_H
#define R_MAP_H

/* For every type, ensure "value.h" is loaded first. */
#include "value.h"
#include "chunk.h"

struct RMapPairT {
  RValue key;
  RValue value;
};
typedef struct RMapPairT RMapPair;

struct RMapT {
  /* Pointer to the buckets */
  RMapPair* buckets;

  /* Number of buckets */
  uint32_t size;

  /* Number of filled buckets */
  uint32_t filled;
};

/**
 * \brief Lookup a key, get a value.
 * \return true if key found in the map. value returned by reference
 * (unchanged if key not found).
 **/
bool r_map_get(RValue map, RValue key, RValue* value);

/**
 * \brief Create a new empty RMap.
 **/
RValue r_map_new();

/**
 * \brief Create a new, empty RMap, to hold at least n elements.
 **/
RValue r_map_new_sized(int n);

/**
 * \brief Set a value in the map (possibly overwriting a previous value if the
 * key already exists in the map).
 * \return true if the value was already in the map.
 **/
bool r_map_set(RValue map, RValue key, RValue value);

#endif /* R_MAP_H */
